#!/bin/bash

k8s_ip=$1
repo_url=$2
node_port=$3
service_name=$4

yaml_path=/data/k8s-deploy/${service_name}/k8s-deployment.yaml
sed -i "s!{{repo_url}}!${repo_url}!g" deploy/k8s-deployment.yaml
sed -i "s/{{nodePort}}/${node_port}/g" deploy/k8s-deployment.yaml
sed -i "s/service-name-zhw/${service_name}/g" deploy/k8s-deployment.yaml

ssh root@${k8s_ip} "rm -rf /data/k8s-deploy/${service_name}"
ssh root@${k8s_ip} "mkdir -p /data/k8s-deploy/${service_name}"
scp deploy/k8s-deployment.yaml root@${k8s_ip}:${yaml_path}

ssh root@${k8s_ip} "kubectl delete -f ${yaml_path}"
ssh root@${k8s_ip} "kubectl apply -f ${yaml_path}"
